using System;
using System.Collections.Generic;
using Core.Domain.Bases;
using Core.Domain.Enums;

namespace Core.Domain.Entities
{
  ///<summary>Ballot cast in an election. This represents the paper ballot received.</summary>
  public class Ballot : EntityBaseWithId
  {
    ///<summary></summary>
    public Ballot()
    {
      this.CreateIndependentInstances();
      Votes = new List<Vote>();
    }


    private IndependentWrapper<string> _code;

    ///<summary>Unique identifier for this ballot. Generated by code. Example: A23. This is written on the paper ballot</summary>
    public virtual string Code
    {
      get { return _code.Value; }
      set { _code.Value = value; }
    }

    private IndependentWrapper<IList<Vote>> _votes;

    /// <summary>List of people voted for (votees) on this ballot</summary>
    public virtual IList<Vote> Votes
    {
      get { return _votes.Value; }
      set { _votes.Value = value; }
    }

    private IndependentWrapper<BallotStatus> _ballotStatus;

    ///<summary>The status of this ballot</summary>
    public virtual BallotStatus BallotStatus
    {
      get { return _ballotStatus.Value; }
      set { _ballotStatus.Value = value; }
    }

    #region Demographics of this Ballot

    private IndependentWrapper<BallotSet> _inBallotSet;

    ///<summary>In what election?</summary>
    public virtual BallotSet InBallotSet
    {
      get { return _inBallotSet.Value; }
      set { _inBallotSet.Value = value; }
    }

    private IndependentWrapper<Teller> _enteredByTeller;

    ///<summary>Teller who typed in this ballot</summary>
    public virtual Teller EnteredByTeller
    {
      get { return _enteredByTeller.Value; }
      set { _enteredByTeller.Value = value; }
    }

    private IndependentWrapper<Teller> _enteredByTellerAssistant;

    ///<summary>Teller who assisted with the entry of this ballot</summary>
    public virtual Teller EnteredByTellerAssistant
    {
      get { return _enteredByTellerAssistant.Value; }
      set { _enteredByTellerAssistant.Value = value; }
    }

    private IndependentWrapper<BallotEntryComputer> _enteredWithComputer;

    ///<summary>Computer used to enter this ballot</summary>
    public virtual BallotEntryComputer EnteredWithComputer
    {
      get { return _enteredWithComputer.Value; }
      set { _enteredWithComputer.Value = value; }
    }

    private IndependentWrapper<VotingLocation> _enteredAtLocation;

    ///<summary>Location where voter is voting</summary>
    public virtual VotingLocation EnteredAtLocation
    {
      get { return _enteredAtLocation.Value; }
      set { _enteredAtLocation.Value = value; }
    }

    #endregion

  }

  public static partial class Extensions
{
    ///<summary>Add a Vote to this Ballot</summary>
    ///<param name="ballot"></param>
    ///<param name="vote"></param>
    public static Ballot Add(this Ballot ballot, Vote vote)
    {
      vote.Ballot = ballot;
      ballot.Votes.Add(vote);
      return ballot;
    }


}
}